package com.baby.routing;

import com.baby.utils.ConnectionUtil;
import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Consumer2 {

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
        //创建队列
        channel.queueDeclare("routing_consumer2",true,false,false,null);
        //绑定
        channel.queueBind("routing_consumer2","routing_exchange","error");
        //获取信息
        Consumer consumer =new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者2获取信息："+new String(body));
            }
        };
        channel.basicConsume("routing_consumer2",true, consumer);

    }

}
